[id].vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="admin--page-content">
  3. <div class="admin--form">
  4. <!-- 낚시지역 상세 -->
  5. <table class="admin--form--table">
  6. <colgroup>
  7. <col style="width: 120px;">
  8. <col>
  9. </colgroup>
  10. <tbody>
  11. <tr>
  12. <th><div>지역명</div></th>
  13. <td>{{ formData.name || "-" }}</td>
  14. </tr>
  15. <tr>
  16. <th><div>등록일</div></th>
  17. <td>{{ formatDateTime(formData.created_at) }}</td>
  18. </tr>
  19. <tr>
  20. <th><div>최근 수정</div></th>
  21. <td>{{ formatDateTime(formData.updated_at) }}</td>
  22. </tr>
  23. </tbody>
  24. </table>
  25. <!-- 버튼 영역 -->
  26. <div class="admin--form-actions">
  27. <button type="button" class="admin--btn" @click="goToList">
  28. ← 목록으로
  29. </button>
  30. <button type="button" class="admin--btn admin--btn-red-border ml--auto" @click="handleDelete">
  31. 삭제
  32. </button>
  33. <button type="button" class="admin--btn admin--btn-red" @click="goToEdit">
  34. 수정
  35. </button>
  36. </div>
  37. <!-- 알림 모달 -->
  38. <AdminAlertModal
  39. v-if="alertModal.show"
  40. :title="alertModal.title"
  41. :message="alertModal.message"
  42. :type="alertModal.type"
  43. @confirm="handleAlertConfirm"
  44. @cancel="handleAlertCancel"
  45. @close="closeAlertModal"
  46. />
  47. </div>
  48. </div>
  49. </template>
  50. <script setup>
  51. import { ref, onMounted } from "vue";
  52. import { useRoute, useRouter } from "vue-router";
  53. import AdminAlertModal from "~/components/admin/AdminAlertModal.vue";
  54. definePageMeta({
  55. layout: "admin",
  56. middleware: ["auth"],
  57. });
  58. const route = useRoute();
  59. const router = useRouter();
  60. const { get, del } = useApi();
  61. const areaId = route.params.id;
  62. const formData = ref({
  63. name: "",
  64. created_at: "",
  65. updated_at: "",
  66. });
  67. // 알림 모달
  68. const alertModal = ref({
  69. show: false,
  70. title: "알림",
  71. message: "",
  72. type: "alert",
  73. onConfirm: null,
  74. });
  75. const showAlert = (message, title = "알림") => {
  76. alertModal.value = { show: true, title, message, type: "alert", onConfirm: null };
  77. };
  78. const showConfirm = (message, onConfirm, title = "확인") => {
  79. alertModal.value = { show: true, title, message, type: "confirm", onConfirm };
  80. };
  81. const closeAlertModal = () => { alertModal.value.show = false; };
  82. const handleAlertConfirm = () => {
  83. if (alertModal.value.onConfirm) alertModal.value.onConfirm();
  84. closeAlertModal();
  85. };
  86. const handleAlertCancel = () => closeAlertModal();
  87. // 상세 조회
  88. const loadDetail = async () => {
  89. const { data, error } = await get(`/area/${areaId}`);
  90. if (error || !data?.success) {
  91. showAlert(error?.message || data?.message || "조회에 실패했습니다.", "오류");
  92. return;
  93. }
  94. const row = data.data || {};
  95. formData.value = {
  96. name: row.name ?? "",
  97. created_at: row.created_at ?? "",
  98. updated_at: row.updated_at ?? "",
  99. };
  100. };
  101. // 삭제
  102. const handleDelete = () => {
  103. showConfirm(
  104. `'${formData.value.name}' 낚시지역을 삭제하시겠습니까?`,
  105. async () => {
  106. const { data, error } = await del(`/area/${areaId}`);
  107. if (error || !data?.success) {
  108. showAlert(error?.message || data?.message || "삭제에 실패했습니다.", "오류");
  109. } else {
  110. showAlert(data.message || "삭제되었습니다.", "성공");
  111. setTimeout(() => router.push("/site-manager/area/list"), 800);
  112. }
  113. },
  114. "낚시지역 삭제"
  115. );
  116. };
  117. // 이동
  118. const goToList = () => router.push("/site-manager/area/list");
  119. const goToEdit = () => router.push(`/site-manager/area/edit/${areaId}`);
  120. // 일시 포맷
  121. const formatDateTime = (dateString) => {
  122. if (!dateString) return "-";
  123. const date = new Date(dateString.replace(" ", "T"));
  124. if (isNaN(date.getTime())) return dateString;
  125. return date.toLocaleString("ko-KR", {
  126. year: "numeric",
  127. month: "2-digit",
  128. day: "2-digit",
  129. hour: "2-digit",
  130. minute: "2-digit",
  131. });
  132. };
  133. onMounted(() => {
  134. loadDetail();
  135. });
  136. </script>